import React from 'react';
import { Table, Form, Checkbox } from 'antd';

const AuthTable = ({ data = [], resourceCodes }) => {
    const authType = {
        1: '菜单',
        2: '页面',
        3: '按钮'
    };
    const levelType = {
        1: '基础',
        2: '职能',
        3: '高级'
    };
    const columns = [
        {
            title: '功能',
            dataIndex: 'name'
        },
        {
            title: '类型',
            dataIndex: 'type',
            render: text => authType[text] || ''
        },
        {
            title: '等级',
            dataIndex: 'gradeType',
            render: (text, record) => (
                <span style={{ color: `${record.gradeType === 3 ? '#F00' : '000'}` }}>{levelType[text] || ''} </span>
            )
        },
        {
            title: '操作',
            dataIndex: 'code',
            render: text => <Checkbox disabled checked={resourceCodes && resourceCodes.includes(text)}></Checkbox>
        }
    ];

    return (
        data.length > 0 && (
            <Table
                bordered={false}
                dataSource={data}
                columns={columns}
                rowKey="code"
                pagination={false}
                style={{ marginTop: 16 }}
                defaultExpandAllRows
            />
        )
    );
};

export default Form.create()(AuthTable);
